# ┌─────────┐
# │ exports │
# └─────────┘

# Platform detection
if [[ "$OSTYPE" == "darwin"* ]]; then
    PLATFORM="macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
    PLATFORM="linux"
else
    PLATFORM="unknown"
fi

# Basic environment
export XDG_CONFIG_HOME="$HOME/.config"
export EDITOR="nvim"
export TERM=xterm-256color
export NVIM_NOTES_NAME="nvim-notes"

# Paths with existence check
paths=($HOME/<->-NOTE/sigma(N) $HOME/note/sigma(N))
[[ -d ${paths[1]} ]] && export OBNOTE=${paths[1]}

export PATH="$HOME/bin:$PATH:$HOME/.local/bin:$HOME/.duckdb/cli/latest"

# Platform-specific paths
if [[ "$PLATFORM" == "macos" ]]; then
    # macOS Homebrew
    if [ -x "/opt/homebrew/bin/brew" ]; then
        eval "$(/opt/homebrew/bin/brew shellenv)"
    fi

    # Go on macOS (typically via Homebrew)
    if command -v brew &> /dev/null && [ -d "$(brew --prefix go)/libexec" ]; then
        export GOROOT=$(brew --prefix go)/libexec
        export GOPATH=$HOME/go
        export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
    fi
elif [[ "$PLATFORM" == "linux" ]]; then
    # Linux Homebrew
    if [ -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
        eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
    fi

    # Go on Linux
    export GOROOT=/usr/lib/go
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

    # Nix LD library path
    export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH
fi

# Additional paths
export PATH="$HOME/.config/emacs/bin:$PATH"
export PATH="$HOME/.venvs/global/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"


# Pager
export MANPAGER="nvim +Man!"

# Load environment file
[ -f "$HOME/.env" ] && source "$HOME/.env"

# Plugin initialization
source $HOME/.config/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $HOME/.config/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# Tool initialization
if command -v fzf &> /dev/null; then
    eval "$(fzf --zsh)"
fi
if command -v zoxide &> /dev/null; then
    if [[ -o interactive ]]; then
        eval "$(zoxide init --cmd cd zsh)"
    else
        eval "$(zoxide init zsh)"
    fi
fi
if command -v starship &> /dev/null; then
    eval "$(starship init zsh)"
fi
if command -v direnv &> /dev/null; then
    eval "$(direnv hook zsh)"
fi


# Ensure pip symlink exists (macOS only)
[[ -d "$HOME/.venvs/global/bin" && -x "$HOME/.venvs/global/bin/pip3.12" && ! -e "$HOME/.venvs/global/bin/pip" ]] && ln -sf pip3.12 "$HOME/.venvs/global/bin/pip"
